<?php
    require_once('../inc/classes/idiorm.class.php');

    // Проверки и подключение Конфигурации
    if(is_file('../config.db')) { 
        include_once '../config.db'; 
        if(!isset($lng)) { 
            $lng="ru"; 
        }    
    } else {
        $mysql_host="localhost";	
        $mysql_user="udbo";
        $mysql_pass="";
        $mysql_base="udbo";    
        $theme     ="default"; 
        $lng       ="ru";
        $version   ="00.00.00.01";
    }
    //
    require_once '../lang/'.$lng.'.db';

    ORM::configure('mysql:host='.$mysql_host.';dbname='.$mysql_base);
    ORM::configure('username', $mysql_user);
    ORM::configure('password', $mysql_pass);

    $query_sql = file_get_contents('SQL\_config_ORM.sql');

    $db = ORM::get_db();
    $db->exec($query_sql);

    if (!empty($_POST)) {

        // Create a new contact object
        $config = ORM::for_table('_config')->create();
        $config->enableduserregister = $_POST['enabled_user_register'];
        $config->enabledsmtp         = $_POST['enabled_smtp'];
        $config->enabledsmtpauth     = $_POST['enabled_smtp_auth'];
        $config->enabledldap         = $_POST['enabled_ldap'];
        $config->version             = $_POST['version'];
        $config->themeamvo           = $_POST['theme_amvo'];
        $config->namesite            = $_POST['name_site'];
        $config->emailadmin          = $_POST['email_admin'];
        $config->smtphost            = $_POST['smtphost'];
        $config->smtpport            = $_POST['smtpport'];
        $config->smtpuser            = $_POST['smtpuser'];
        $config->smtppassword        = $_POST['smtppassword'];
        $config->ldaphost            = $_POST['ldaphost'];
        $config->ldapport            = $_POST['ldapport'];
        $config->ldapuser            = $_POST['ldapuser'];
        $config->ldappassword        = $_POST['ldappassword'];
        $config->ldapdn              = $_POST['ldapdn'];

        // Save the object to the database
        $config->save();

        // Redirect to self.
        header('Location: ' . basename(__FILE__));
        exit;
    }
    
    $count = ORM::for_table('_config')->count();
    $contact_list = ORM::for_table('_config')->find_many();    
?>

<html>
    <head>
        <title><?php echo $lng_install['_Title'];?></title>
    </head>

    <body>
    
        <h1><?php echo $lng_install['_Title'];?></h1>

        <h2>Настройки программы</h2>
        <ul>
            <?php foreach ($contact_list as $contact): ?>            
            <li><strong><?php echo $lng_install['_enableduserregister']; ?><code><?php echo $contact->enableduserregister; ?></code></strong></li>
            <li><strong><?php echo $lng_install['_enabledsmtp']; ?><code><?php echo $contact->enabledsmtp; ?></code></strong></li>
            <li><strong><code><?php echo $contact->enabledsmtpauth; ?></code></strong></li>
            <li><strong><code><?php echo $contact->enabledldap; ?></code></strong></li>
            <li><strong><code><?php echo $contact->version; ?></code></strong></li>
            <li><strong><code><?php echo $contact->themeamvo; ?></code></strong></li>
            <li><strong><code><?php echo $contact->namesite; ?></code></strong></li>
            <li><strong><code><?php echo $contact->emailadmin; ?></code></strong></li>
            <li><strong><code><?php echo $contact->smtphost; ?></code></strong></li>
            <li><strong><code><?php echo $contact->smtpport; ?></code></strong></li>
            <li><strong><code><?php echo $contact->smtpuser; ?></code></strong></li>
            <li><strong><code><?php echo $contact->smtppassword; ?></code></strong></li>
            <li><strong><code><?php echo $contact->ldaphost; ?></code></strong></li>
            <li><strong><code><?php echo $contact->ldapport; ?></code></strong></li>
            <li><strong><code><?php echo $contact->ldapuser; ?></code></strong></li>
            <li><strong><code><?php echo $contact->ldappassword; ?></code></strong></li>
            <li><strong><code><?php echo $contact->ldapdn; ?></code></strong></li>
            <?php endforeach; ?>
        </ul>

        <form method="post" action="">
            <h2><?php echo $lng_install['_ConfigForm'];?></h2>
            <p><label for="enabled_user_register">enabled_user_register:</label> <input type="text" name="enabled_user_register" /></p>
            <p><label for="enabled_smtp">enabled_smtp:</label> <input type="text" name="enabled_smtp" /></p>
            <p><label for="enabled_smtp_auth">enabled_smtp_auth:</label> <input type="text" name="enabled_smtp_auth" /></p>
            <p><label for="enabled_ldap">enabled_ldap:</label> <input type="text" name="enabled_ldap" /></p>
            <p><label for="version">version:</label> <input type="text" name="version" /></p>
            <p><label for="theme_amvo">theme_amvo:</label> <input type="text" name="theme_amvo" /></p>
            <p><label for="name_site">name_site:</label> <input type="text" name="name_site" /></p>
            <p><label for="email_admin">email_admin:</label> <input type="text" name="email_admin" /></p>
            <p><label for="smtphost">smtphost:</label> <input type="text" name="smtphost" /></p>
            <p><label for="smtpport">smtpport:</label> <input type="text" name="smtpport" /></p>
            <p><label for="smtpuser">smtpuser:</label> <input type="text" name="smtpuser" /></p>            
            <p><label for="smtppassword">smtppassword:</label> <input type="text" name="smtppassword" /></p>            
            <p><label for="ldaphost">ldaphost:</label> <input type="text" name="ldaphost" /></p>            
            <p><label for="ldapport">ldapport:</label> <input type="text" name="ldapport" /></p>            
            <p><label for="ldapuser">ldapuser:</label> <input type="text" name="ldapuser" /></p>            
            <p><label for="ldappassword">ldappassword:</label> <input type="text" name="ldappassword" /></p>                        
            <p><label for="ldapdn">ldapdn:</label> <input type="text" name="ldapdn" /></p>                        
            <input type="submit" value="Create" />
        </form>
    </body>
</html>